package com.example.demo.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileManipulation {
    public static void main(String[] args) {
        String inputFile = "E:\\2023101609点03分文章\\上传服务器最终版\\1-20231016092947.txt";
        String outputFile1 = "E:\\output1.txt";
        String outputFile2 = "E:\\output2.txt";
        String additionalString = "<p><img class=\"ue-image\" src=\"{#ZC_BLOG_HOST#}zb_users/upload/2023/11/202311151700016964992178.jpg\" title=\"guanggao.jpg\" alt=\"guanggao.jpg\" width=\"1382\" height=\"779\" style=\"width: 1382px; height: 779px;\"/></p>";

        try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
             BufferedWriter writer1 = new BufferedWriter(new FileWriter(outputFile1));
             BufferedWriter writer2 = new BufferedWriter(new FileWriter(outputFile2))) {

            String line;
            while ((line = reader.readLine()) != null) {
                int index = line.indexOf("******");
                if (index != -1) {
                    String beforeString = line.substring(0, index);
                    writer1.write(beforeString);
                    writer1.newLine();

                    String afterString = additionalString + line.substring(index + 6);
                    writer2.write(afterString);
                    writer2.newLine();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}